#include<fcntl.h>
#include<stdio.h>
#include<unistd.h>
#include<fcntl.h>
#include<string.h>

int main()
{
    const char* file1 = "a.txt";
    const char* file2 = "b.txt";

    int fd1 = open(file1,O_RDWR|O_APPEND);
    int fd2 = open(file2, O_RDWR|O_APPEND);

    char buff1[1024];
    char buff2[1024];

    int ret1 = read(fd1, buff1, sizeof(buff1) - 1);
    int ret2 = read(fd2, buff2, sizeof(buff2) - 1);

    buff1[ret1] = '\0';
    buff2[ret2] = '\0';

    write(fd1, buff2, strlen(buff2) - 1);
    write(fd2, buff1, strlen(buff1) - 1);

    return 0;
}